package com.huaxonline.boot.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaxonline.boot.demo.dto.DemoDTO;
import com.huaxonline.boot.demo.dto.DemoParam;
import com.huaxonline.boot.demo.entity.Demo;
import com.huaxonline.boot.demo.mapper.DemoMapper;
import com.huaxonline.boot.demo.service.IDemoService;
import com.huaxonline.boot.web.pojo.param.QueryPage;
import com.huaxonline.boot.web.pojo.response.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhaoshulei
 * @since 2020-05-08
 */
@Service
public class DemoServiceImpl extends ServiceImpl<DemoMapper, Demo> implements IDemoService {

    @Override
    public List<Demo> getAllList() {
        return this.getBaseMapper().selectList(Wrappers.query());
    }

    @Override
    public PageResult<DemoDTO> getPageList(DemoParam demoParam) {
        IPage<Demo> page = this.page(new QueryPage(demoParam), Wrappers.query());
        return new PageResult<DemoDTO>(page, this::toDemoDTO);
    }

    public DemoDTO toDemoDTO(Demo demo) {
        DemoDTO demoDTO = new DemoDTO();
        demoDTO.setId(demo.getId());
        demoDTO.setSupplierCode(demo.getSupplierCode());
        demoDTO.setSupplierName(demo.getSupplierName());
        demoDTO.setRiskCode(demo.getRiskCode());
        demoDTO.setRiskName(demo.getRiskName());
        return demoDTO;
    }

}
